package com.example.content.views

import android.content.Context
import android.view.View
import android.view.animation.Animation
import android.widget.TextView
import com.example.content.App
import com.example.content.R
import razerdp.basepopup.BasePopupWindow
import razerdp.util.animation.AnimationHelper
import razerdp.util.animation.TranslationConfig

/**
 * Created by zhudongao
 * Desc
 * Date 2020/11/24
 */
class RewardCoinPop(val context: Context) : BasePopupWindow(context) {
    override fun onCreateContentView(): View {
        val coinView = createPopupById(R.layout.reward_pop_layout)
        val coin20 = coinView.findViewById<View>(R.id.coin_20)
        val coin60 = coinView.findViewById<View>(R.id.coin_60)
        val coin450 = coinView.findViewById<View>(R.id.coin_450)
        val coin880 = coinView.findViewById<View>(R.id.coin_880)
        val coinCustom = coinView.findViewById<View>(R.id.coin_custom)
        val coinContainer = coinView.findViewById<View>(R.id.coin_container)
        val customContainer = coinView.findViewById<View>(R.id.custom_coin_container)
        val consumer = coinView.findViewById<TextView>(R.id.consumer)
        val cancel = coinView.findViewById<View>(R.id.cancel)
        val close = coinView.findViewById<View>(R.id.close)
        cancel.setOnClickListener {
            this.dismiss()
        }
        close.setOnClickListener {
            this.dismiss()
        }
        coin20.setOnClickListener {
            consumer.text = App.appContext.getString(R.string.real_money, 2)
            coin20.isSelected = true
            coin60.isSelected = false
            coin450.isSelected = false
            coin880.isSelected = false
        }
        coin60.setOnClickListener {
            consumer.text = App.appContext.getString(R.string.real_money, 6)
            coin20.isSelected = false
            coin60.isSelected = true
            coin450.isSelected = false
            coin880.isSelected = false
        }
        coin450.setOnClickListener {
            consumer.text = App.appContext.getString(R.string.real_money, 45)
            coin20.isSelected = false
            coin60.isSelected = false
            coin450.isSelected = true
            coin880.isSelected = false
        }
        coin880.setOnClickListener {
            consumer.text = App.appContext.getString(R.string.real_money, 88)
            coin20.isSelected = false
            coin60.isSelected = false
            coin450.isSelected = false
            coin880.isSelected = true
        }
        coinCustom.setOnClickListener {
            coinContainer.visibility = View.GONE
            customContainer.visibility = View.VISIBLE
            coin20.isSelected = false
            coin60.isSelected = false
            coin450.isSelected = false
            coin880.isSelected = false
        }
        coin20.isSelected = true
        consumer.text = App.appContext.getString(R.string.real_money, 2)
        return coinView
    }

    override fun onCreateShowAnimation(): Animation {
        return AnimationHelper.asAnimation()
            .withTranslation(TranslationConfig.FROM_BOTTOM)
            .toShow()
    }
}